<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>vaeThink</title>
  {include file="../common/header"}
</head>
<body class="vae-body">

<div class="vae-content">
  <fieldset class="layui-elem-field layui-field-title" >
    <legend>呼叫任务投放</legend>
  </fieldset>
  <form class="layui-form layui-form-pane" action="">{:token()}
    <div class="layui-form-item">
      <label class="layui-form-label">任务名字</label>
      <div class="layui-input-block">
        <input type="text" name="name" autocomplete="off" placeholder="任务名" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">任务目的</label>
      <div class="layui-input-block">
        <input type="text" name="aim" autocomplete="off" placeholder="本次任务目的" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">Excel编码</label>
      <div class="layui-input-block">
        <textarea placeholder="请输入内容：E2019818,E2019819" class="layui-textarea" name="enumber" required >{foreach $excelList as $val}{$val.number},{/foreach}
        </textarea>
      </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title" >
      <legend>客服组</legend>
    </fieldset>
    <div id="user-group">
      <div class="user-g">
        <div class="layui-form-item ">
          <label class="layui-form-label">客服组</label>
          <div class="layui-input-inline">
            <select  lay-filter="user-group" name="group" lay-search="" class="user-group" id="0">
              <option value="">请选择客服组</option>
              {foreach $userGroup as $val}
              <option value="{$val.id}">{$val.name}</option>
              {/foreach}
            </select>
          </div>
          <div>
            <button type="button" class="layui-btn layui-btn-primary user-group-add">加一组成员 + </button>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">组成员</label>
          <div class="layui-input-block user-u">
          </div>
        </div>
      </div>
    </div>
    <fieldset class="layui-elem-field layui-field-title" >
      <legend>短信配置</legend>
    </fieldset>
    <div id="sms-group">
      <div class="sms-data">
        <div class="layui-form-item ">
          <label class="layui-form-label">短信分类</label>
          <div class="layui-input-inline">
            <select name="quiz1" lay-filter="sms-group" lay-search=""  class="sms-group" lang="0">
              <option value="">请选择短信类别</option>
              {foreach $smsType  as $val}
              <option value="{$val.id}">{$val.name}</option>
              {/foreach}
            </select>
          </div>
          <div>
            <button type="button" class="layui-btn layui-btn-primary sms-add">加一组短信 + </button>
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">短信模板</label>
          <div class="layui-input-block sms-info">
          </div>
        </div>
      </div>
    </div>

    <div class="layui-form-item layui-form-text">
      <label class="layui-form-label">简介</label>
      <div class="layui-input-block">
        <textarea placeholder="请输入内容" class="layui-textarea" name="intro" required ></textarea>
      </div>
    </div>
    <div class="layui-form-item">
      <button class="layui-btn" lay-submit="" lay-filter="vaeform">立即提交</button>
    </div>
  </form>
</div>






{include file="../common/footer"}

<script>
layui.config({
    base: '/themes/admin_themes/module/'
}).use(['vaeyo','form'], function(){
  var table = layui.table
  ,vae = layui.vaeyo
  ,$ = layui.$
  ,form = layui.form;


  form.on('select(user-group)', function(data){
    var id=data.value;
    var index=data.elem.id;
    $(".user-u:eq("+index+")").html("");
    console.log(data);
    $.post("{:url('CallTask/getGroupUserList')}",{'id':id},function (data) {
        $(data).each(function () {
          $(".user-u:eq("+index+")").append("<input type=\"checkbox\" name=\"users[]\" value="+this.id+" title="+this.nickname+":"+this.number+">\n")
        })
      form.render();
    })
    form.render();
  });

  $(".user-group-add").click(function () {
    var id=$(".user-group:last").attr('id');
    id++;
    $("#user-group").append($(".user-g:last").clone(true));
    $(".user-u:last").html("");
    $(".user-group:last").attr('id',id);
    form.render();
  })

  form.on('select(sms-group)', function(data){
    var id=data.value;
    var index=data.elem.lang;
    $(".sms-info:eq("+index+")").html("");
    console.log(index);
    $.post("{:url('CallTask/getGroupSmsList')}",{'id':id},function (data) {
      $(data).each(function () {
        $(".sms-info:eq("+index+")").append("<input type=\"checkbox\" name=\"sms[]\" value="+this.id+" title="+this.uniqid+":"+this.title+">\n")
      })
      form.render();
    })
    form.render();
  });


  $(".sms-add").click(function () {
    var id=$(".sms-group:last").attr('lang');
    id++;
    $("#sms-group").append($(".sms-data:last").clone(true));
    $(".sms-info:last").html("");
    $(".sms-group:last").attr('lang',id);
    form.render();
  })

  //监听提交
  form.on('submit(vaeform)', function(data){
    $.ajax({
      url:"{:url('CallTask/taskAdd')}",
      type:'post',
      data:data.field,
      success:function(e){
        if(e.code==1){
          layer.confirm('保存成功,返回列表页吗?', {icon: 3, title:'提示'}, function(index){
            vae.backThisTab();
            layer.close(index);
          });
        }else{
          layer.msg(e.msg);
        }
      }
    })
    return false;
  });
});
</script>

</body>
</html>